package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.PictureAddNewDTO;
import cn.tedu.csmall.product.service.IPictureService;
import cn.tedu.csmall.product.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@Api(tags = "照片的控制器")
@RequestMapping("/picture")
public class PictureController {
    @Autowired
    private IPictureService service;

    @ApiOperation("添加图片")
    @PostMapping("/addNew")
    public JsonResult<Void> addNew(PictureAddNewDTO addNewDTO){
        log.debug("开始处理添加照片，参数是：{}",addNewDTO);
        service.addNew(addNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除图片")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id){
        log.debug("开始处理删除照片，id是：{}",id);
        service.deleteById(id);
        return JsonResult.ok();
    }
}
